<template>
	<!-- 分类 -->
	<view class="category">
		<view class="nav">
			<scroll-view class="bg" scroll-y="true" scroll-top="0" :scroll-with-animation="true">
				<view class="nav_item" :class="{'ac':current == index }" v-for="(item,index) in cate" :key="index"
					@click="clickNav(index)">
					<view v-if="current == index" class="line"></view>
					{{item.name}}
				</view>
			</scroll-view>
		</view>
		<view class="goodsBox">
			<scroll-view class="rightlab" scroll-y="true">
				<view class="goods">
					<view class="empty" v-if="cate[current].sunList.length == 0">
						<u-empty mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png">
						</u-empty>
					</view>
					<view class="goods_item" v-for="(item1,inde) in cate[current].sunList" :key="inde">
						<view class="third" @click="godetail(item1.id)">
							<image class="th_img" :src="oss(item1.image)" mode=""></image>
							<view class="title">{{item1.name}}</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				active: 0,
				current: 0,
				scrollTop: 0,
				height: 0,
				barHeight: 0,
				cate: []
			}
		},
		onLoad(options) {
			this.barHeight = uni.getSystemInfoSync().statusBarHeight;
			if(options.index){
				this.current = options.index
			}
			
			// this.getlist()
			this.getcates()
		},
		methods: {
			clickNav(index) {
				this.current = index;
			},
			// 跳转详情
			godetail(id) {
				// console.log(id)
				uni.$u.route({
					url: 'pages/common/classlist',
					params: {
						id: id
					}
				})
			},
			// // 获取商品分类
			getcates() {
				uni.$u.http.post('/freecate').then(res => {
					if (res.code == 1) {
						console.log(res.data)
						this.cate = res.data
					}
				}).catch((res) => {
				
				})
			},
			// 跳转分类列表
			// goclass(ids) {
			// 	uni.$u.route({
			// 		url: 'pagesA/index/detail/cladetail',
			// 		params: {
			// 			id: ids
			// 		}
			// 	})
			// }

		}

	}
</script>
<style scoped lang="scss">
	.category {
		height: 100vh;
		display: flex;

		.nav {
			flex: 1;
			display: flex;
			flex-direction: column;

			.bg {
				// position: relative;
				background: #F7F8F9;
				height: 100vh;


				.nav_item {
					
					width: 200rpx;
					height: 104rpx;
					text-align: center;
					font-size: 30rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #333333;
					display: flex;
					align-items: center;
					justify-content: center;
					background-color: #f5f5f5;
					position: relative;
					
					.line{
						margin-right: 10rpx;
						width: 8rpx;
						height: 28rpx;
						background: #FEBF4E;
						border-radius: 4px 4px 4px 4px;
					}
				}
				
				

				.bos {
					position: absolute;
					left: 0;
					width: 4px;
					height: 40rpx;
					background: $u-main-color;
				}




				.ac {
					color: $u-main-color;
					font-size: 30rpx;
					background: #ffffff;
				}

				// .ac::after {
				// 	content: "";
				// 	width: 5rpx;
				// 	height: 60rpx;
				// 	position: absolute;
				// 	// top: 0;
				// 	left: 0;
				// 	background: $u-main-color;
				// }
			}

		}

		.goodsBox {
			flex: 3;
			padding-left: 10rpx;
			background-color: #ffffff;

			.empty {
				margin: auto;
			}

			.rightlab {
				height: 100vh;

			}

			.goods {
				display: flex;
				flex-direction: row;
				flex-wrap: wrap;
				padding: 30rpx 0;

				.goods_item {
					display: flex;
					flex-direction: column;
					flex-basis: 33%;

					.third {
						display: flex;
						flex-direction: column;
						justify-content: center;
						align-items: center;
						padding: 10rpx 0rpx;


						.th_img {
							border-radius: 10rpx;
							width: 80rpx;
							height: 80rpx;
						}

						.title {
							overflow: hidden;
							text-overflow: ellipsis;
							-o-text-overflow: ellipsis;
							-webkit-text-overflow: ellipsis;
							-moz-text-overflow: ellipsis;
							white-space: nowrap;
							margin-top: 15rpx;
							font-size: 24rpx;
							font-family: PingFang SC;
							font-weight: 400;
							color: #333333;
						}
					}


				}
			}
		}
	}
</style>
